<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/27
 * Time: 14:19
 */

namespace app\crm\controller;


use app\crm\model\ConfigParam;

class Param extends BaseController
{
    public function setUrl()
    {
        $url = ConfigParam::where('key', 'url')->value('value_str');
        $this->assign('url', $url);
        return $this->fetch();
    }

    public function setUrlHandle()
    {
        $url = input('url');
        $res = ConfigParam::where('key','url')->setField('value_str',$url);
        if ($res === false){
            return json(['errrorCode'=>1,'msg'=>'修改失败']);
        }
        return json(['errrorCode'=>0,'msg'=>'修改成功']);
    }

    public function setBonus()
    {
        $param = ConfigParam::where('key', ['=', 'pool_base'], ['=', 'weight_base'],  'or')->column('key,value');
        $this->assign('param', $param);
        return $this->fetch();
    }

    public function setBonusHandle(){
        $pool_base = input('post.pool_base');
        $weight_base = input('post.weight_base');
        $res = ConfigParam::where('key','pool_base')->setInc('value',$pool_base);
        $res = ConfigParam::where('key','weight_base')->setInc('value',$weight_base);
        if ($res === false){
            return json(['errrorCode'=>1,'msg'=>'修改失败']);
        }
        return json(['errrorCode'=>0,'msg'=>'修改成功']);
    }
}